﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Text.RegularExpressions;

public partial class AreaManSc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["group"] == null)
        {
            Response.Redirect("../Login.aspx");
        }
        else if ((int)Session["group"] != 2)
        {
            Response.Redirect("../Login.aspx");
        }

        SqlConnection sqlcon = null;
        SqlCommand sqlcmd = null, sqlcmd2 = null;
        string cmd = "", cmd2 = "";
        SqlDataReader rd;
        sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString);
        sqlcon.Open();
        cmd = "select id,address,score from Node where area=" + Session["areaid"] + ";";
        sqlcmd = new SqlCommand(cmd, sqlcon);
        SqlDataAdapter da = new SqlDataAdapter(cmd, sqlcon);
        DataSet ds = new DataSet();
        da.Fill(ds, "anyway");
        if (!IsPostBack)
        {
            DropDownList1.DataSource = ds.Tables["anyway"].DefaultView;
            DropDownList1.DataTextField = "address";
            DropDownList1.DataValueField = "id";
            DropDownList1.DataBind();
            cmd2 = "select score from Node where id='" + DropDownList1.SelectedValue + "';";
            sqlcmd2 = new SqlCommand(cmd2, sqlcon);
            rd = sqlcmd2.ExecuteReader();
            if (rd.Read())
            {
                Label5.Text = rd[0].ToString();
            }
        }
        sqlcon.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Session["uid"] != null && RadioButtonList1.SelectedValue!="")
        {
            SqlConnection sqlcon = null;
            SqlCommand sqlcmd = null, sqlcmd2 = null;
            string cmd = "", cmd2 = "";
            SqlDataReader rd;
            sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString); //sqlcon = new SqlConnection(constring);
            sqlcon.Open();
            cmd = "update Node set score = " + RadioButtonList1.SelectedValue + ",stime = '" + DateTime.Today.ToShortDateString() + "' where id = '" + DropDownList1.SelectedValue + "';";
            sqlcmd = new SqlCommand(cmd, sqlcon);
            sqlcmd.ExecuteNonQuery();
            cmd2 = "select score from Node where id='" + DropDownList1.SelectedValue + "';";
            sqlcmd2 = new SqlCommand(cmd2, sqlcon);
            rd = sqlcmd2.ExecuteReader();
            if (rd.Read())
            {
                Label5.Text = rd[0].ToString();
            }
            Label7.Visible = true;
            sqlcon.Close();
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection sqlcon = null;
        SqlCommand sqlcmd2 = null;
        string cmd2 = "";
        SqlDataReader rd;
        sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["testLottery"].ConnectionString); //sqlcon = new SqlConnection(constring);
        sqlcon.Open();
        cmd2 = "select score from Node where id='" + DropDownList1.SelectedValue + "';";
        sqlcmd2 = new SqlCommand(cmd2, sqlcon);
        rd = sqlcmd2.ExecuteReader();
        if (rd.Read())
        {
            Label5.Text = rd[0].ToString();
        }
        sqlcon.Close();
    }
}